<template>
  <div class="HospitalGroup">
    <el-form ref="hospitalForm" :model="hospitalForm" :rules="rules">
      <el-form-item prop="hospitalIds">
        <el-checkbox-group v-model="hospitalForm.hospitalIds">
          <el-checkbox v-for="item in hospitalList" :key="item.id" :label="item.id">{{ item.hospitalName }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'HospitalGroup',
  props: {
    hospitalList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      hospitalForm: {
        hospitalIds: []
      },
      rules: {
        hospitalIds: [{
          required: true, message: '请勾选至少一个医院', trigger: 'change'
        }]
      }
    }
  },
  methods: {
    setData(data) {
      this.hospitalForm.hospitalIds = data
    },
    getData() {
      let isValidate
      this.$refs.hospitalForm.validate(v => {
        if (v) {
          isValidate = true
        }
      })
      console.log(isValidate)
      if (isValidate) {
        return this.hospitalForm.hospitalIds
      }
    }
  }
}
</script>

<style scoped>

</style>
